package cn.miju.admin.system.controller;

import cn.miju.admin.framework.model.BaseInfo;
import cn.miju.admin.framework.model.BasePage;
import cn.miju.admin.system.service.RoleService;
import cn.miju.admin.system.vo.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <pre>
 * 角色管理
 * </pre>
 *
 * @author zhuming
 * @version 1.0.0
 * @since 2023-04-03 14:38
 */
@RestController
@Api(tags = "系统-角色管理")
@ApiSort(4)
@RequestMapping("/system/role")
public class RoleController {
    private final RoleService service;

    public RoleController(RoleService service) {
        this.service = service;
    }

    /**
     * 角色分页查询
     * @param inVO {@link RolePageInVO}
     * @return {@link Page<RolePageOutVO>}
     */
    @ApiOperation("角色分页查询")
    @ApiOperationSupport(order = 1, author = "zhuming")
    @GetMapping("/page")
    public Page<RolePageOutVO> getPage(@ModelAttribute @Validated RolePageInVO inVO) {
        return service.getPage(inVO);
    }

    /**
     * 保存角色信息
     * @param inVO {@link RoleSaveInVO}
     */
    @ApiOperation("保存角色信息")
    @ApiOperationSupport(order = 2, author = "zhuming")
    @PostMapping("/save")
    public void save(@RequestBody @Validated RoleSaveInVO inVO) {
        service.save(inVO);
    }

    /**
     * 批量删除角色
     * @param inVO {@link RoleDeleteInVO}
     */
    @ApiOperation("批量删除角色")
    @ApiOperationSupport(order = 3, author = "zhuming")
    @PostMapping("/deletes")
    public void deletes(@RequestBody @Validated RoleDeleteInVO inVO) {
        service.deletes(inVO);
    }

    /**
     * 获取角色树
     * @return {@link List<RoleTreeOutVO>}
     */
    @ApiOperation("获取角色树")
    @ApiOperationSupport(order = 4, author = "zhuming")
    @GetMapping("/tree")
    public List<RoleTreeOutVO> getTree() {
        return service.getTree();
    }
}
